import logging
import time
import yagmail

# 读取yaml文件
import yaml
def open_yaml():
    with open(r'D:\gao62301a\zoukaogao6\yuekao\Until\yaml.yaml','r',encoding='utf-8') as p:
        return yaml.safe_load(p)

def open_yaml1():
    with open(r'D:\gao62301a\zoukaogao6\yuekao\Until\yamladd.yaml','r',encoding='utf-8') as p:
        return yaml.safe_load(p)

t=time.strftime('%Y%m%d-%H%M%S',time.localtime())
def get_logger(name='test_jiekou'):
    logger=logging.getLogger(name)
    if not logger.handlers:
        fmt=logging.Formatter('%(filename)s-%(levelname)s-%(asctime)s-%(message)s')
        file=logging.FileHandler(f'{t}.txt',encoding='utf-8')
        file.setFormatter(fmt)
        logger.addHandler(file)

        con=logging.StreamHandler()
        con.setFormatter(fmt)
        logger.addHandler(con)

    return logger

def get_log():
    logging.basicConfig(filename='log.txt',filemode='w+',format='%(filename)s-%(levelname)s-%(asctime)s-%(message)s',level=logging.DEBUG)

def email(file):
    email=yagmail.SMTP(user='1441688225@qq.com',password='subvcobnwlujggee',host='smtp.qq.com')
    email.send(to='1441688225@qq.com',subject='接口自动化',contents='这是关于接口的增删改查自动化',attachments=file)